﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using TransactionServer.OSActivities;
using TransactionServer.General_Classes;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TransactionServer.Connectors.Test
{
    [TestClass]
    public class OSConnectorTests
    {
        OSConnector connector;

        [TestMethod]
        public void TestOSGetObjects()
        {
            var attributes = new List<string> {"Код", "Ссылка", "Наименование"};
            var filter = new Filter();
            attributes.ForEach(attribute => filter.attributes.Add(new CAttribute(attribute)));

            filter.conditions.Add(new CCondition("ЭтоГруппа", "=", "Ложь"));
            filter.conditions.Add(new CCondition("Наименование", "=", "Атата"));

            filter.entity = "Справочники.Номенклатура";

            var entities = connector.getObjects(filter);

            Assert.AreEqual(1, entities.Count);
        }

        [TestMethod]
        public void TestOSGetObjectsTablePart()
        {
            var attributes = new List<string> { "Номенклатура", "Количество" };
            var filter = new Filter();
            attributes.ForEach(attribute => filter.attributes.Add(new CAttribute(attribute)));

            filter.conditions.Add(new CCondition("Цена", ">", "100"));
            filter.conditions.Add(new CCondition("Ссылка", "=", "{\"#\",0bf5eb6f-2a20-4f53-bfa7-8bab452a27e5,200:bea900155d05fa0611e1c53620d590b5}"));

            filter.entity = "ТабличныеЧасти.Документы.ЗаказПокупателя.Товары";

            var entities = connector.getObjects(filter);

            Assert.AreEqual(1, entities.Count);
        }

        public OSConnectorTests()
        {
            connector = new OSConnector(new Dictionary<string, string> 
            { 
                { "path", @"D:\Проекты\1CBase\" }, 
                { "user", "" }, 
                { "password", "" }, 
            });
        }
    }
}
